package com.lww.feature.test.design.pattern.prototype;

import org.junit.Test;

/**
 * @author: liweiwei
 * @date: 2019/1/22
 */
public class PrototypePattern {

    @Test
    public void cloneTest() throws CloneNotSupportedException {
        Stove stove = new Stove();
        stove.setBrand("1brand");
        CookHouse cookHouse = new CookHouse();
        cookHouse.setArea("1area");
        cookHouse.setStove(stove);
//        House house = new House();
        House house = new DeepCloneHouse();
        house.setNo("1no");
        house.setCookHouse(cookHouse);
        house.setAge(1);
        System.out.println("1===========");
        System.out.println(house.getNo()+"|"+house.getCookHouse().getArea()+"|"+house.getCookHouse().getStove().getBrand());

        House cloneHouse = (House)house.clone();
        cloneHouse.setNo("2no");

        cloneHouse.getCookHouse().setArea("2area");
        cloneHouse.getCookHouse().getStove().setBrand("2brand");

        System.out.println("1===========");
        System.out.println(house.getNo()+"|"+house.getCookHouse().getArea()+"|"+house.getCookHouse().getStove().getBrand());

        System.out.println("2===========");
        System.out.println(cloneHouse.getNo()+"|"+cloneHouse.getAge()+"|"+cloneHouse.getCookHouse().getArea()+"|"+cloneHouse.getCookHouse().getStove().getBrand());




    }

}
